﻿using Codeflows;
using CodeflowsTests.Scenarios;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CodeflowsTests
{
    [TestClass]
    public class ArgumentExtractorTests
    {
        [TestMethod]
        public void WhenArgumentsAreExtracted_ResultShouldContain_TheMehodName()
        {
            var ae = new ArgumentParser<Echo>();
            var result = ae.Parse(e => e.Start("hello"));
            Assert.AreEqual("Start", result.ActionName);
        }

        [TestMethod]
        public void WhenArgumentsAreExtracted_ResultShouldContain_AnEntryForEachArgument()
        {
            var ae = new ArgumentParser<Echo>();
            var result = ae.Parse(e => e.Start("hello"));
            Assert.AreEqual("hello", result.Arguments["greeting"]);
        }

        [TestMethod]
        public void FieldAccessExpressionsAreHandled()
        {
            var g = "hello";
            var ae = new ArgumentParser<Echo>();
            var result = ae.Parse(e => e.Start(g));
            Assert.AreEqual("hello", result.Arguments["greeting"]);
        }

        [TestMethod]
        public void PropertyAccessExpressionsAreHandled()
        {
            var ct = new ComplexType { Greeting =  "Hello" };
            var ae = new ArgumentParser<Echo>();
            var result = ae.Parse(e => e.Start(ct.Greeting));
            Assert.AreEqual(ct.Greeting, result.Arguments["greeting"]);
        }

        [TestMethod]
        public void ParametersAreHandled()
        {
            var ct = new ComplexType {Greeting = "Hello"};
            TestIt(ct);
        }

        void TestIt(ComplexType complexType)
        {
            var ae = new ArgumentParser<Echo>();
            var result = ae.Parse(e => e.Start(complexType.Greeting));
            Assert.AreEqual(complexType.Greeting, result.Arguments["greeting"]);
        }
    }

    class ComplexType
    {
        public string Greeting { get; set; }
    }
}
